home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Directorty Opus 5 - Magellan
/
Opus 5 - Magellan.iso
/
Extras
/
MailBox1.5
/
MailBox.dopus5
< prev
next >
Wrap
Text File
|
1996-10-25
|
10KB
|
342 lines
/* MailBox ARexx Module for Directory Opus 5.5
©1996 Mark Rigby-Jones for mrjsw
mark.rigby-jones@keble.oxford.ac.uk <*> http://users.ox.ac.uk/~kebl0206/
$VER: MailBox.dopus5 1.5 (25.10.96)
For information on usage, see the supplied MailBox.guide file. */
/*---------------------------------Settings---------------------------------*/
MailFile = "Home:Mail/mrj" /* The mailbox file to monitor */
EmptyIcon = "DOpus5:Icons/mail_empty" /* icon to display for no mail */
OldIcon = "DOpus5:Icons/mail_old" /* icon to display for old mail */
NewIcon = "DOpus5:Icons/mail_new" /* icon to display for new mail */
MailPort = "T:MailRdy" /* Port to listen on for new mail */
SnapFile = "DOpus5:System/MailBox.snap" /* File to store snapshot position */
StartUp = "yes" /* Open icon on startup yes/no */
ILock = 0 /* Initial lock state 0=yes/1=no */
/*-------------------------------End Settings-------------------------------*/
Options Results
Options FailAt 11
Signal On Syntax
Parse Arg DOpusPort Function Source Dest Cmd
Cmd=Upper(Cmd)
Address Value DOpusPort
If ~Show("L","rexxsupport.library") Then
Call AddLib("rexxsupport.library",0,-30,0)
/* Module initialised by DOpus */
If Function = "init" Then Do
DOpus Command "MailBox" Program "MailBox" Desc "'Open/Close/Refresh MailBox'" Template "CLOSE/S"
If StartUp = "no" Then Exit
End
/* If MailBox is already running, send appropriate
commands to it rather than opening an icon ourselves. */
Call Forbid()
If Show(P,MailPort) Then Do
Call Permit()
Address Value MailPort
If Cmd = "CLOSE" Then
Close
Else
Refresh
Exit
End
If Cmd="CLOSE" Then Exit
/* Try to open our message port. */
If ~OpenPort(MailPort) Then Do
Call Permit()
DOpus Request '"MailBox: Unable to open message port 'MailPort'" OK'
Exit
End
Call Permit()
/* Read a previously snapshotted position. */
If Open(FileHandle,SnapFile) Then Do
Position = "Pos "ReadLn(FileHandle)
ILock = ReadCh(FileHandle)
Call Close(FileHandle)
End
Else Do
Position = ""
End
IconName = ""
Mails = 0
Size = -1
Flag = 3
stem.COUNT = 5
stem.0 = "Lock"
stem.1 = "Un-Lock"
stem.2 = "---"
stem.3 = "Refresh"
stem.4 = "Mailer..."
/* Main Loop */
Do Until Flag<0
/* Do we want to refresh the icon? */
If Flag>0 Then Do
RefreshTime = Time()
/* Get the size of the mailbox. */
If Exists(MailFile) Then Do
NewSize = Word(StateF(MailFile),2)
NewIconName = OldIcon
End
Else Do
NewSize = 0
NewIconName = EmptyIcon
End
/* New mail message recieved (but we check to see
that the mailbox has increased in size too. */
If (Flag=2 & NewSize>Size) Then Do
DOpus SetAppIcon IconHandle Busy On
/*---------------------------------New Mail---------------------------------*/
/* Example: Play a sample
'Command Play Quiet Work:Music/Samples/newmail'
*/
/*-------------------------------End New Mail-------------------------------*/
Address Value DOpusPort
DOpus SetAppIcon IconHandle Busy Off
Mails = Mails+1
LastTime = RefreshTime
Plural = "s"
If Mails = 1 Then Do
OldSize = Size
Plural = ""
End
End
If Mails>0 Then
NewIconName = NewIcon
Size=NewSize
KSize = (512+Size)%1024
/* Create text for icon and information requester. */
Select
When Size=0 Then Do
Label = "No mail"
About = 'no email whatsoever'
End
When Mails>0 Then Do
NSize = (512+Size-OldSize)%1024
Label = Mails" New, "NSize"K"
About = KSize'K of email, of which 'Nsize'K,'||'0A'x||Mails' message'Plural', is new. The last'||'0A'x||'mail arrived at 'LastTime
End
Otherwise
Label = KSize"K old mail"
About = KSize'K of email, none new'
End
/* Update the icon and/or text. */
If NewIconName ~= IconName Then Do
If Flag ~= 3 Then
DOpus RemAppIcon IconHandle
IconName = NewIconName
DOpus AddAppIcon MailPort '"'Label'"' 1 Position Icon '"'IconName'"' Info Snap Close Local Menu stem.
IconHandle = RESULT
End
Else
DOpus SetAppIcon IconHandle Text '"'Label'"'
If ILock Then
DOpus SetAppIcon IconHandle Locked On
End
/* Wait for a message to the message port. */
Flag = 0
Call WaitPkt(MailPort)
Packet = GetPkt(MailPort)
If Packet=Null() Then
/* Not an ARexx message, assume it's about new mail. */
Flag=2
Else Do
/* Parse input to find out what the command is. */
Cmd=UPPER(GetArg(Packet,0))
If (Cmd="SNAPSHOT" | Cmd="DROPFROM" | Cmd="MENU") Then
Data = GetArg(Packet,2)
Call Reply(Packet,0)
If Cmd = "MENU" Then Do
Select
When Data = 0 Then
Cmd = "LOCK"
When Data = 1 Then
Cmd = "UNLOCK"
When Data = 3 Then
Cmd = "REFRESH"
When Data = 4 Then
Cmd = "DOUBLECLICK"
End
End
If Cmd = "MENUHELP" Then
Cmd = "INFO"
/* Now process that command. */
Select
When Cmd = "REFRESH" Then
Flag = 1
When Cmd = "CLOSE" Then
Flag = -1
When Cmd = "REMOVED" Then
Flag = -2
When Cmd = "INFO" Then Do
/* Information requester - some of
the text was generated earlier. */
DOpus SetAppIcon IconHandle Busy On
DOpus Request '"MailBox for Directory Opus 5.5'||'A'x||'©1996 Mark Rigby-Jones'||'0A0A'x||'As of 'RefreshTime', you have'||'0A'x||About'." OK|Close'
If RC = 0 Then
Flag = -1
Dopus SetAppIcon IconHandle Busy Off
End
When Cmd = "SNAPSHOT" Then Do
/* Icon snapshot - save it to the specified file. */
Position = "Pos "Data
If Open(FileHandle,SnapFile,W) Then Do
Call WriteLn(FileHandle,Data)
Call WriteCh(FileHAndle,ILock)
Call Close(FileHandle)
End
End
When Cmd = "UNSNAPSHOT" Then Do
/* Unsnapshot icon - delete the file. */
Position = ""
Call Delete(SnapFile)
End
When Cmd = "LOCK" Then Do
ILock = 1
DOpus SetAppIcon IconHandle Locked On
End
When Cmd = "UNLOCK" Then Do
ILock = 0
DOpus SetAppIcon IconHandle Locked Off
End
When Cmd = "DOUBLECLICK" Then Do
/* Icon double-clicked - put the icon in busy-mode whilst
we execute user code, and reset the new mail count. */
DOpus SetAppIcon IconHandle Busy On
/*-------------------------------Go To Mailer-------------------------------*/
/* Example: Load/Bring to front Mailer
This routine works with MetaTool 40.5, assuming you
have some ScreenToFront Program.
If ~Show(P,"METATOOL") Then
Address COMMAND "Run Home:MetaTool/MetaTool"
Else Do
Address METATOOL "SHOW"
Address COMMAND "ScreenToFront MetaTool"
End
*/
/*-----------------------------End Go To Mailer-----------------------------*/
Address Value DOpusPort
DOpus SetAppIcon IconHandle Busy Off
Mails = 0
Flag = 1
End
When Cmd = "DROPFROM" Then Do
/* Icon double-clicked - put the icon in
busy-mode whilst we execute user code. */
DOpus SetAppIcon IconHandle Busy On
/*------------------------Files Dropped on AppIcon--------------------------*/
/* Example: Load mailbox into your mailer?
Add file as attatchment?
*/
/*----------------------End Files Dropped on AppIcon------------------------*/
Address Value DOpusPort
DOpus SetAppIcon IconHandle Busy Off
Flag = 1
End
Otherwise
/* Not a recognised command - assume it's about new mail. */
Flag = 2
End
End
End
/* Exit cleanly for whatever reason. */
If Flag = -1 Then
DOpus RemAppIcon IconHandle
Call ClosePort(MailPort)
Exit
/* Syntax error ocurred - exit cleanly with a helpful message. */
Syntax:
Call ClosePort(MailPort)
DOpus RemAppIcon IconHandle
DOpus Request '"MailBox: Error, line 'SIGL' : 'ErrorText(RC)'" OK'
Exit